Jon W{tte, Svartmangatan 18, S-111 29 Stockholm, Sweden
h+@nada.kth.se +46-10-141652
My landlord have forbidden my cat to run around on the roof.
+++++++++++++++++++++++++++
From: rbarris@orion.oac.uci.edu (Robert C. Barris)
Organization: University of California, Irvine
Date: 6 Aug 92 05:47:42 GMT
In article <D88-JWA.92Aug4142157@cyklop.nada.kth.se> d88-jwa@cyklop.nada.kth.se (Jon W{tte) writes:
>
>This is the dying sound channel from hell problem.
>
>I am playing some sounds, asynchronously, and sometimes
>(repeatable but not predictable) the sound channel just
>dies and doesn't play anymore. Re-initting the channel
>makes sound come back.
I have seen this and had to deal with it.
In a nutshell, the Sound Manager is not perfect. If it misses an interrupt
from the ASC for any reason (LocalTalk is popular cause) then it just forgets
about that output channel (and it never gets fed again).
I encountered this problem when using SndPlayDoubleBuffer, and ultimately
implemented a watchdog routine which kept track of the number of ticks
elapsed since the last block of data transferred to the sound chip. If that
number ever went above a certain threshold, it figured 'oops, the channel
stalled' and re-initted it as you mentioned.
Obviously it would be nice if the SndMgr did this for us.
Rob Barris
Quicksilver Software Inc.
rbarris@orion.oac.uci.edu
---------------------------
From: essam@gagme.chi.il.us (Essam Khairullah)
Subject: Setting the volume
Organization: Gagme Public Access UNIX, Chicago, Illinois.
Date: Mon, 3 Aug 1992 20:08:50 GMT
I've been trying to write an XCMD to set the speaker volume (in THINK C 5.0) and
I have this weird problem....
Basically I originally tried reading the parameter RAM, changing the appropriate
bits for the sound volume, and then writing it back. I then discovered the low
memory global SdVolume. Both methods seemed to work, except for the following
problem:
Basically the sound volume would not be effected until I activate AfterDark (by
moving the mouse into the appropriate corner) or I open the Sound control panel
and play a sound. If I just SysBeep without doing one of the above things firstthe old volume would be used. But if I do one of the above, the sound volume
that I was trying to set would be used.
My XCMD is actually an XFCN which also returns the current sound volume. If I
call it again after setting the volume, the volume it returns is also the right
volume.
What am I doing wrong? Do I need to do something like InitSoundManager (which
as far as IM 1-6 are concerned, doesn't exist). Do I have to open a new sound
channel or something? Please let me know if you have any advice!
Thanks in advance...
- --
Essam Badi' Abu Khalil Khairullah
essam@gagme.chi.il.us
I don't got no fancy signature!
I'm a .signature virus. You can't resist copying me into your .signature!
+++++++++++++++++++++++++++
From: jeremyr@dcs.qmw.ac.uk (Jeremy Roussak)
Date: 6 Aug 92 18:23:13 GMT
Organization: Computer Science Dept, QMW, University of London
In <1992Aug3.200850.14026@gagme.chi.il.us> essam@gagme.chi.il.us (Essam Khairullah) writes:
>I've been trying to write an XCMD to set the speaker volume...
>Basically I originally tried reading the parameter RAM, changing the appropriate
>bits for the sound volume, and then writing it back. I then discovered the low
>memory global SdVolume. Both methods seemed to work, except for the following
>problem:
[changes not activated until After Dark run]
>What am I doing wrong?
There are two relevant low-memory globals. SpVolCtl is a byte
which reflects the parameter RAM volume setting in its low 3
bits. SdVolume is a byte which contains the current speaker
volume.
GetSoundVolume() returns the current value of SdVolume.
SetSoundVolume(short) sets SdVolume to the specified value,
with immediate effect, but the change will not persist after
restart.
Changing the low 3 bits of SpVolCtl and then calling WriteParam
makes a change which will come into effect after restart, or
perhaps after running the Sound CP.
So,
to change the volume, call GetSoundVolume and SetSoundVolume:
don't forget to be responsible and call SetSoundVolume again to
restore the level
to make a permanent change, do the above and also set SpVolCtl
and call WriteParam.
I think the above is correct :-)
Jeremy
---------------------------
From: psc9q@holmes.acc.Virginia.EDU (The Beloved)
Subject: I need a *fast* rand () procedure
Organization: University of Virginia
Date: Wed, 5 Aug 1992 06:25:00 GMT
Hello,
I'm creating bitmaps filled with a certain percentage of dots. Basically, I
just test to see if "rand () % 100" is less than say, 25%, and draw a point.
Does anyone know of a faster way to do this? I've rewritten rand.c in assembly
but only received a 50% speed improvement. I need something drastically
faster. Below is my assembly code. Could I optimize this somehow?
unsigned long newRand = 1;
int fastrand ()
{
unsigned int tempRand;
asm
{
move.l newRand, d0
mulu.l #1103515245, d0
add.w #12345, d0
move.l d0, newRand
lsr.l #8, d0
lsr.l #8, d0
and.w #32767, d0
move.w d0, tempRand
}
return (tempRand);
}
Thanks,
Paul
- --
beloved@virginia.edu "Top one, nice one, get sorted."
psc9q@holmes.acc.virginia.edu -- Altern8
+++++++++++++++++++++++++++
From: buckeye@spf.trw.com (John Wallace)
Organization: TRW Data Systems Center, Redondo Beach, CA
Date: Wed, 5 Aug 92 20:42:59 GMT
In article <1992Aug5.062500.17133@murdoch.acc.Virginia.EDU> psc9q@holmes.acc.Virginia.EDU (The Beloved) writes:
>Hello,
>
>I'm creating bitmaps filled with a certain percentage of dots. Basically, I
>just test to see if "rand () % 100" is less than say, 25%, and draw a point.
>Does anyone know of a faster way to do this? I've rewritten rand.c in assembly
>but only received a 50% speed improvement. I need something drastically
>faster. Below is my assembly code. Could I optimize this somehow?
>
>unsigned long newRand = 1;
>
>int fastrand ()
>{
> unsigned int tempRand;
>
> asm
> {
> move.l newRand, d0
> mulu.l #1103515245, d0
> add.w #12345, d0
> move.l d0, newRand
> lsr.l #8, d0
> lsr.l #8, d0
> and.w #32767, d0
> move.w d0, tempRand
> }
>
> return (tempRand);
>}
>
>Thanks,
>
>Paul
>--
>beloved@virginia.edu "Top one, nice one, get sorted."
>psc9q@holmes.acc.virginia.edu -- Altern8
There are a couple of things you may want to do to speed things up.
Rather than shifting by 16, just call the 'swap' command to move the
high word into the low word. Also, why do you add 32767? This will
just convert all of your positives into negatives and your negatives
into positives, so it seems to be of no possible value.
Also rather than doing it rand()%100, you may want to do it
rand()%128, which you would implement as rand()&127, since the %
operation is quite slow. Then rather than comparing it to 25, you can
compare it to 25*(128/100), where you compute that value only once outside of
your pixel plotting code.
You may also want to the the %128 operation in the code itself, and
since C returns values in d0 (I think; I do most of my high level
coding in Pascal), you could recode the entire thing as:
unsigned long newRand = 1;
int RandMod128 ()
{
asm
{
move.l newRand, d0
mulu.l #1103515245, d0
add.w #12345, d0
move.l d0, newRand
swap d0 ; move high word of random value into low word
and.w #127,d0 ; get value in range from 0..127
unlink a6 ; undo the C routine's link a6
rts ; return to caller
}
}
Cheers!
John
- -------------
John Wallace buckeye@spf.trw.com
+++++++++++++++++++++++++++
From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
Organization: Kalamazoo College
Date: Wed, 5 Aug 1992 21:43:15 GMT
I don't want to pick on you, John, but I just have to say this... :-)
buckeye@spf.trw.com (John Wallace) writes:
>psc9q@holmes.acc.Virginia.EDU (The Beloved) writes:
>>
>>I'm creating bitmaps filled with a certain percentage of dots. Basically, I
>>just test to see if "rand () % 100" is less than say, 25%, and draw a point.
>
>There are a couple of things you may want to do to speed things up.
>Rather than shifting by 16, just call the 'swap' command to move the
>high word into the low word.
True--twice as fast...
>Also, why do you add 32767?
He 'and'ed, which masks off the lower 16 bits (which doesn't affect the
result, in this case...)
>Also rather than doing it rand()%100, you may want to do it
>rand()%128, which you would implement as rand()&127, since the %
>operation is quite slow. Then rather than comparing it to 25, you can
>compare it to 25*(128/100)
In C, 25*(128/100) equals 25. I suspect you want (25*128)/100.
>...since C returns values in d0 (I think; I do most of my high level
>coding in Pascal), you could recode...:
>
>int RandMod128 ()
>{
> asm
> {
> move.l newRand, d0
> mulu.l #1103515245, d0
> add.w #12345, d0
> move.l d0, newRand
> swap d0 ; move high word of random value into low word
> and.w #127,d0 ; get value in range from 0..127
> unlink a6 ; undo the C routine's link a6
> rts ; return to caller
> }
>}
This will work (except that "unlink" is spelled "unlk"), but, as the
manual says, "Do not use the RTS instruction unless you're absolutely
sure you know what you're doing. If you want to return a value, always
use a return statement."
In this case, I believe the compiler won't be smart enough to realize
you're returning inside the asm block, and will put its own unlk and rts
right after yours. More important (to me) is the unlk that matches up
with the hidden one at the top of the function. If you rewrite
RandMod128 to use a local variable, you'd better be alert enough to
catch this. This kind of coding makes me nervous.
If speed is so important that you can't take the time to push and pop
the return value, you should be inlining this function anyway, and
putting both newRand and the constant #12345 into registers if at all
possible.
Finally, I hope this code won't be run on a 68000; it doesn't have a